/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

import { HvigorLogger } from '../../../log/hvigor-log.js';

export class PluginContext {
  protected logger: HvigorLogger = HvigorLogger.getLogger(PluginContext.name);

  private contextMap = new Map<string, Function>();

  setContextFunc(pluginId: string, func: Function): void {
    this.contextMap.set(pluginId, func);
  }

  getContext(pluginId: string): any {
    const func = this.contextMap.get(pluginId);
    if (!this.contextMap.has(pluginId) || typeof func !== 'function') {
      return undefined;
    }
    return (func as Function)();
  }
}
